package com.hospicpc.demos.mapper;

import com.hospicpc.demos.entity.Messages;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lse
 * @since 2024-03-18
 */
@Mapper
public interface MessagesMapper extends BaseMapper<Messages> {
    @Insert("insert into messages(messageId, senderId, receiverId, avatar_url,messageContent, sendTime, isRead) values(#{messageid}, #{senderid}, #{receiverid}, #{avatarUrl},#{messagecontent}, #{sendtime}, 0)")
    void insertMessages(Messages messages);
    @Select("select * from messages where senderId = #{userId} or receiverId = #{userId}")
    List<Messages> getMessagesLists(@Param("userId") String userId);
    @Select("select senderId, receiverId, avatar_url, messageContent, sendTime from messages where (receiverId = #{userId} and senderId = #{sendId}) or (receiverId = #{sendId} and senderId = #{userId}) ORDER BY sendTime ")
    List<Messages> getMessages(@Param("sendId") String sendId, @Param("userId") String userId);
    @Update("update messages set isRead = 1 where senderId = #{sendId} and receiverId = #{userId}")
    void isReadMessages(@Param("sendId") String sendId, @Param("userId") String userId                          );
}
